home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 December: Technology Seed / ATS Dec. '97.toast / Navigation Services SDK 1.0b1 / Examples / Sampler / Sampler ƒ / Offscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  2.0 KB  |  85 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Offscreen.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment AppSeg
  9.  
  10. #ifndef Common_Defs
  11. #include "Common.h"
  12. #endif
  13.  
  14.  
  15. // *****************************************************************************
  16. // *
  17. // *    DrawOffscreen()
  18. // *
  19. // *****************************************************************************
  20. WindowOffscreen* DrawOffscreen(WindowPtr theWindow)
  21. {    
  22.     WindowOffscreen*    theOffscreen;
  23.     GWorldPtr            theWorld;
  24.     Rect                globalRect;
  25.     Rect                bounds = theWindow->portRect;
  26.  
  27.     if ((theOffscreen = (WindowOffscreen*)NewPtr(sizeof(WindowOffscreen))) == 0L)
  28.         return(0L);
  29.  
  30.     SetPort(theWindow);
  31.     
  32.     GetGWorld(&theOffscreen->windowPort,&theOffscreen->windowDevice);
  33.  
  34.     globalRect = bounds;
  35.     LocalToGlobal((Point*)&globalRect.top);
  36.     LocalToGlobal((Point*)&globalRect.bottom);
  37.  
  38.     if (NewGWorld(&theWorld,0,&globalRect,0L,0L,0) == noErr)
  39.         {
  40.         Rect bounds = theWindow->portRect;
  41.  
  42.         SetGWorld(theWorld, 0L);
  43.         if (!LockPixels(theWorld->portPixMap))
  44.             {
  45.             DisposeGWorld(theWorld);
  46.             DisposePtr((Ptr)theOffscreen);
  47.             return(0L);
  48.             }
  49.  
  50.         //••!! CopyBits((BitMap*)&((theWindow->port)->portPixMap),&((GrafPtr)theWorld)->portBits,&bounds,&theWorld->portRect,srcCopy,0L);
  51.  
  52.         theOffscreen->offscreenWorld = theWorld;
  53.         return theOffscreen;
  54.         }
  55.     else
  56.         {
  57.         DisposePtr((Ptr)theOffscreen);
  58.         return 0L;
  59.         }
  60. }
  61.  
  62.  
  63. // *****************************************************************************
  64. // *
  65. // *    DrawOnscreen()
  66. // *
  67. // *****************************************************************************
  68. void DrawOnscreen(WindowOffscreen* theOffscreen)
  69. {
  70.     if (theOffscreen)
  71.         {
  72.         SetGWorld(theOffscreen->windowPort,theOffscreen->windowDevice);
  73.         
  74.         CopyBits(&((GrafPtr)theOffscreen->offscreenWorld)->portBits,
  75.                 (const BitMap*) &(theOffscreen->windowPort)->portPixMap,
  76.                  &theOffscreen->offscreenWorld->portRect,
  77.                  &theOffscreen->windowPort->portRect,
  78.                  srcCopy,0L);
  79.                  
  80.         UnlockPixels(theOffscreen->offscreenWorld->portPixMap);
  81.         DisposeGWorld(theOffscreen->offscreenWorld);
  82.         DisposePtr((Ptr)theOffscreen);
  83.         }
  84. }
  85.